/*
 * @Author: szx
 * @Date: 2022-06-14 12:05:06
 * @LastEditTime: 2022-06-14 12:06:26
 * @Description:
 * @FilePath: \leetcode\面试题\17\09\09.js
 */
/**
 * @param {number} k
 * @return {number}
 */
var getKthMagicNumber = function (k) {
    const dp = new Array(k).fill(0);
    dp[0] = 1;
    let p3 = 0,
        p5 = 0,
        p7 = 0;
    for (let i = 1; i < k; i++) {
        const num1 = dp[p3] * 3;
        const num2 = dp[p5] * 5;
        const num3 = dp[p7] * 7;
        dp[i] = Math.min(num1, Math.min(num2, num3));
        if (dp[i] == num1) p3++;
        if (dp[i] == num2) p5++;
        if (dp[i] == num3) p7++;
    }
    return dp[k - 1];
};
